package org.moonlight.jvm.natives.java.lang.string;

import org.moonlight.jvm.natives.AbstractNativeMethod;
import org.moonlight.jvm.rtda.exclusive.Frame;
import org.moonlight.jvm.rtda.share.Object;
import org.moonlight.jvm.rtda.share.methodarea.StringPool;

/**
 * java.lang.String public native String intern();
 *
 * @author Moonlight
 * @createTime 2023/9/22 16:17
 **/
public class Intern extends AbstractNativeMethod {

    public Intern() {
        super("java/lang/String","intern","()Ljava/lang/String;");
    }

    @Override
    public void nativeMethod(Frame frame) {
        Object that = frame.getLocalVars().getThis();
        Object interned = StringPool.internString(that);
        frame.getOperandStack().pushRef(interned);
    }

}
